updating oE is_even_obj

is_even_obj

include math.e 
namespace math 
public function is_even_obj(object test_object) 

tests if the supplied Euphoria object is even or odd.

Parameters:
  1. test_object : any Euphoria object. The item to test.
Returns:

An object,

  • If test_object is an integer...
    • 1 if its even.
    • 0 if its odd.
  • Otherwise if test_object is an atom this always returns 0
  • otherwise if test_object is an sequence it tests each element recursively, returning a sequence of the same structure containing ones and zeros for each element. A 1 means that the element at this position was even otherwise it was odd.
Example 1:
for i = 1 to 5 do 
  ? {i, is_even_obj(i)} 
end for 
-- output ...  
-- {1,0} 
-- {2,1} 
-- {3,0} 
-- {4,1} 
-- {5,0} 
Example 2:
? is_even_obj(3.4) --> 0  
Example 3:
? is_even_obj({{1,2,3}, {{4,5},6,{7,8}},9}) --> {{0,1,0},{{1,0},1,{0,1}},0} 
Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu